// ==UserScript==
// @name           kaskusBetaQuickReply
// @namespace      com.orangdalam.blogsome
// @version		   1.0
// @description    quick reply for kaskus beta
// @include        http://livebeta.kaskus.us/thread/*
// @include        http://livebeta.kaskus.us/post/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// @require        http://kkcdn-static.kaskus.us/css_v0.1/js/editor/jquery.markitup.js
// @require        http://kkcdn-static.kaskus.us/css_v0.1/js/editor/kaskus_bbcode.js
// @author         Adamantoi
// @contributor    sandi_okta (Kaskus UID:241759)

// ==/UserScript==
// */
// still messy code, will update regularly ^_^!
//################recapcay##########################
//- var myscript = document.createElement('script');
//- myscript.setAttribute('src', 'http://kkcdn-static.kaskus.us/css_v0.1/js/editor/jquery.markitup.js');
//- document.body.appendChild(myscript);

 var myscript2= document.createElement('script');
 myscript2.setAttribute('src','http://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
 document.body.appendChild(myscript2);

//Recaptcha.widget = Recaptcha.$("recaptcha_widget_div"); Recaptcha.challenge_callback();
// Recaptcha.create("6LfHgr0SAAAAAJpO_2DyRtpHECySrGkF_XINc5-d",recaptcha_widget_div,{theme:"red",callback: Recaptcha.focus_response_field});


//##########################################################

var jimat = document.getElementById('securitytoken').value;
//alert(jimat);

//var postButton = document.getElementsByClass("new-reply");
var postURL = $('a.new-reply').attr('href');
//alert(postURL);

var target = document.getElementById("thread-footer");
var qr = document.createElement("div");
qr.innerHTML='<a href=# id=aQR name=aQR> '+
			'<form method="post" name="postreply" action="'+postURL+'">	'+
			'<input type="hidden" value="'+jimat+'" name="securitytoken">			'+
				'<fieldset id="pilset"> '+

				'<table id="meja-qr" ><tr>'+
				'<td>'+
						'<div class="reply-message" id="pesan">'+
							'<div class="message">'+

							//'<ul><li class="markItUpButton markItUpButton1 "><a title="Bold" href="">Bold</a></li><li class="markItUpButton markItUpButton2 "><a title="Italic" href="">Italic</a></li><li class="markItUpButton markItUpButton3 "><a title="Underline" href="">Underline</a></li><li class="markItUpSeparator">---------------</li><li class="markItUpButton markItUpButton4 "><a title="Align Left" href="">Align Left</a></li><li class="markItUpButton markItUpButton5 "><a title="Align Center" href="">Align Center</a></li><li class="markItUpButton markItUpButton6 "><a title="Align Right" href="">Align Right</a></li><li class="markItUpSeparator">---------------</li><li class="markItUpButton markItUpButton7 "><a title="Bulleted list" href="">Bulleted list</a></li><li class="markItUpButton markItUpButton8 "><a title="Numeric list" href="">Numeric list</a></li><li class="markItUpButton markItUpButton9 "><a title="Increase Indent" href="">Increase Indent</a></li><li class="markItUpButton markItUpButton10 "><a title="Decrease Indent" href="">Decrease Indent</a></li><li class="markItUpSeparator">---------------</li><li class="markItUpButton markItUpButton11 "><a title="Insert Link [Ctrl+L]" accesskey="L" href="">Insert Link</a></li><li class="markItUpButton markItUpButton12 "><a title="Remove Link" href="">Remove Link</a></li><li class="markItUpButton markItUpButton13 "><a title="Insert Email Link" href="">Insert Email Link</a></li><li class="markItUpButton markItUpButton14 "><a title="Picture [Ctrl+P]" accesskey="P" href="">Picture</a></li><li class="markItUpSeparator">---------------</li><li class="markItUpButton markItUpButton15 "><a title="Wrap [QUOTE] around text" href="">Wrap [QUOTE] around text</a></li><li class="markItUpButton markItUpButton16 "><a title="Wrap [CODE] around text" href="">Wrap [CODE] around text</a></li><li class="markItUpButton markItUpButton17 clean"><a title="Clear Text Formatting" href="">Clear Text Formatting</a></li><br><br><li class="markItUpButton markItUpButton18  markItUpDropMenu"><a title="Colors" href="">Colors</a><ul><li class="markItUpButton markItUpButton18-1 col1-1"><a title="Yellow" href="">Yellow</a></li><li class="markItUpButton markItUpButton18-2 col1-2"><a title="Orange" href="">Orange</a></li><li class="markItUpButton markItUpButton18-3 col1-3"><a title="Red" href="">Red</a></li><li class="markItUpButton markItUpButton18-4 col2-1"><a title="Blue" href="">Blue</a></li><li class="markItUpButton markItUpButton18-5 col2-2"><a title="Purple" href="">Purple</a></li><li class="markItUpButton markItUpButton18-6 col2-3"><a title="Green" href="">Green</a></li><li class="markItUpButton markItUpButton18-7 col3-1"><a title="White" href="">White</a></li><li class="markItUpButton markItUpButton18-8 col3-2"><a title="Gray" href="">Gray</a></li><li class="markItUpButton markItUpButton18-9 col3-3"><a title="Black" href="">Black</a></li></ul></li><li class="markItUpButton markItUpButton19 fonts markItUpDropMenu"><a title="Fonts" href="">Fonts</a><ul><li class="markItUpButton markItUpButton19-1 font-arial"><a title="Arial" href="">Arial</a></li><li class="markItUpButton markItUpButton19-2 font-arialblack"><a title="Arial Black" href="">Arial Black</a></li><li class="markItUpButton markItUpButton19-3 font-arialnarrow"><a title="Arial Narrow" href="">Arial Narrow</a></li><li class="markItUpButton markItUpButton19-4 font-bookantiqua"><a title="Book Antiqua" href="">Book Antiqua</a></li><li class="markItUpButton markItUpButton19-5 font-centurygothic"><a title="Century Gothic" href="">Century Gothic</a></li><li class="markItUpButton markItUpButton19-6 font-comicsansms"><a title="Comic Sans MS" href="">Comic Sans MS</a></li><li class="markItUpButton markItUpButton19-7 font-couriernew"><a title="Courier New" href="">Courier New</a></li><li class="markItUpButton markItUpButton19-8 font-georgia"><a title="Georgia" href="">Georgia</a></li><li class="markItUpButton markItUpButton19-9 font-impact"><a title="Impact" href="">Impact</a></li><li class="markItUpButton markItUpButton19-10 font-lucidaconsole"><a title="Lucida Console" href="">Lucida Console</a></li><li class="markItUpButton markItUpButton19-11 font-timesnewroman"><a title="Times New Roman" href="">Times New Roman</a></li><li class="markItUpButton markItUpButton19-12 font-Trebucher"><a title="Trebucher" href="">Trebucher</a></li><li class="markItUpButton markItUpButton19-13 font-Verdana"><a title="Verdana" href="">Verdana</a></li></ul></li><li class="markItUpButton markItUpButton20 size markItUpDropMenu"><a title="Size" href="">Size</a><ul><li class="markItUpButton markItUpButton20-1 size-1"><a title="1" href="">1</a></li><li class="markItUpButton markItUpButton20-2 size-2"><a title="2" href="">2</a></li><li class="markItUpButton markItUpButton20-3 size-3"><a title="3" href="">3</a></li><li class="markItUpButton markItUpButton20-4 size-4"><a title="4" href="">4</a></li><li class="markItUpButton markItUpButton20-5 size-5"><a title="5" href="">5</a></li><li class="markItUpButton markItUpButton20-6 size-6"><a title="6" href="">6</a></li><li class="markItUpButton markItUpButton20-7 size-7"><a title="7" href="">7</a></li></ul></li><li class="markItUpSeparator">---------------</li><li class="markItUpButton markItUpButton21 "><a title="Wrap [SPOILER] around text" href="">Wrap [SPOILER] around text</a></li><li class="markItUpButton markItUpButton22 "><a title="Embedding video from Youtube " href="">Embedding video from Youtube </a></li><li class="markItUpButton markItUpButton23 "><a title="Embedding video from Vimeo" href="">Embedding video from Vimeo</a></li></ul></div>'+

							'<textarea id="reply-messsage" rows="140" name="message" style="height:170px;width:520px!important" class="markItUpEditor"></textarea>'+


							'</div>'+
							'</div>'+
						'</div>'+
						'</td>'+
								//##########capcay###################
						'<td width="30%">'+
				'<div class="capcay_div" style="padding-top:15px">'+
						'<fieldset class="fieldset">'+
						  '<div dir="ltr">'+
							'<div style="" id="recaptcha_widget_div" class="recaptcha_nothad_incorrect_sol recaptcha_isnot_showing_audio"> '+
							'<noscript><iframe src="http://api.recaptcha.net/noscript?k=6LfHgr0SAAAAAJpO_2DyRtpHECySrGkF_XINc5-d" height="300" width="400" frameborder="0"></iframe>'+
							  ' </div>'+
							   '<br />'+
							   '<textarea name="recaptcha_challenge_field" rows="3" cols="40">'+
							   '</textarea>'+
							   '<input type="hidden" name="recaptcha_response_field" value="manual_challenge" /></noscript>'+
							'</div>'+
						  '</div>'+
						'</fieldset>'+
					'</div>'+
				//################ end capcay ##########################
						''+
						'</div>'+
					'</div>'+
				'</fieldset>'+
				'</td></tr>'+
				'<tr><td><div class=pesan><span id=spMQ></span><p>*Gunakan CTRL+Q untuk akses quick reply secara cepat</p><p>**Jika dalam 5 detik capcay belum muncul, refresh atau lebih baik post biasa</p></div></td><td><input type="submit" accesskey="s" value="Submit Quick Reply" name="sbutton" class="button medium" style="float:right;"></td></tr>'+
				'<tr><td colspan=2 id=kom_manual></td></tr>'+
				'</table>'+

'</form>';

target.parentNode.insertBefore(qr,target);
GM_addStyle("#pilset{background-color:#EEEEEE;} #recaptcha_table,#recaptcha_area{width:310px!important} #meja-qr tr td,#meja-qr tr{border:0 none!important;} #recaptcha_image{padding:0px 0px!important;} .pesan{font-size:10px}");
//Recaptcha.widget = Recaptcha.$("recaptcha_widget_div"); Recaptcha.challenge_callback();

setTimeout(function(){Recaptcha = unsafeWindow.Recaptcha; Recaptcha.create("6LfHgr0SAAAAAJpO_2DyRtpHECySrGkF_XINc5-d","recaptcha_widget_div",{theme:"red"})},5000);
//document.body.appendChild(myscript);
var isCtrl = false;
$(document).keyup(function (e) {
if(e.which == 17) isCtrl=false;
}).keydown(function (e) {
    if(e.which == 17) isCtrl=true;
    if(e.which == 81 && isCtrl == true) {
		$('a.new-reply').focus();
 	return false;
 }
});

for(var i=0;i<document.getElementsByTagName('*').length;i++){
	if(document.getElementsByTagName('*')[i].className == 'entry-footer'){
		var btnQR = document.createElement("input");
		btnQR.setAttribute('class','button quote');
		btnQR.setAttribute('value','Quick Reply');
		JumptoQR(btnQR);
		document.getElementsByTagName('*')[i].appendChild(btnQR);
	}
}

function JumptoQR(el){
	el.addEventListener("click",function(){
		window.location.hash="aQR";
		document.getElementById('reply-messsage').focus();
	}, false);
}


// MULTIQUOTE

var spMQ = document.getElementById('spMQ');
var sMQ 	= document.createElement("span");
sMQ.setAttribute('style','cursor:pointer');
spMQ.appendChild(sMQ);
var tMQ	= document.createTextNode("Fetch Multi Quote");

sMQ.appendChild(tMQ);
ClickMQ(sMQ);

function ClickMQ(el){
	el.addEventListener("click",function(){

		var dataMQ =getCookie('kaskus_multiquote').split(',');
		count = false
		for (i=0;i < dataMQ.length ; i++  )		{
			$('#mq_'+ dataMQ[i]).attr('class','button multi-quote');
		}

		GM_xmlhttpRequest({
			method: 'GET',
			url: 'http://livebeta.kaskus.us/post_reply/'+$('#thread_id').val()+'',
			headers: {
				'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
				'Accept': 'application/atom+xml,application/xml,text/xml',
			},
	     onload: function (responseDetails) {
	       var dt = document.implementation.createDocumentType("html",
	           "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd"),
	         doc = document.implementation.createDocument('', '', dt),
	         html = doc.createElement('html');

	       html.innerHTML = responseDetails.responseText;
	       doc.appendChild(html);
	       document.getElementById('reply-messsage').value = doc.getElementById('reply-messsage').value;
	     }

		});
	}, false);
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)    {
			return unescape(y);
    	}
  	}
}

$(document).ready(function()	{
	$('#reply-messsage').markItUp(kaskusBbcodeSettings);
});





